class String

  def to_money
    # Get the currency
    matches = scan /([A-Z]{2,3})/
    currency = matches[0] ? matches[0][0] : Money.default_currency

    # Get the cents amount
    matches = gsub(/,/, '').scan(/(\-?\d+(\.(\d+))?)/)
    cents = matches[0] ? (matches[0][0].to_f * 100) : 0

    Money.new(cents, currency)
  end

  def commify
    reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/, '\1,').reverse
  end

end
